import QtQuick
import QtQuick.Controls
import QtQuick.Effects

Item {
    id: root

    property string albumSource: ""
    property int albumCoverRaduis: 0
    Image {
        id: _coverImage
        asynchronous: true
        mipmap: true
        source: root.albumSource
        fillMode: Image.PreserveAspectFit
        anchors.fill: parent
        anchors.margins: 5
        onStatusChanged: {
            visible = false;
            _infoTxt.visible = true;
            if (_coverImage.status == Image.Error) {
                _infoTxt.text = "加载\n失败";
            } else if (_coverImage.status == Image.Loading) {
                _infoTxt.text = "正在\n加载";
            } else {
                if (root.albumSource) {
                    visible = true;
                    _infoTxt.visible = false;
                } else {
                    _infoTxt.text = "暂无\n封面";
                }
            }
        }
        layer.enabled: true
        layer.effect: MultiEffect {
            maskEnabled: true
            maskSource: _maskRect
        }
        Rectangle {
            id: _maskRect
            anchors.fill: parent
            radius: root.albumCoverRaduis
            visible: false
            layer.enabled: true
        }
    }
    Label {
        id: _infoTxt
        text: "暂无\n封面"
        anchors.fill: parent
        anchors.margins: 5
        font.pixelSize: parent.width / 2 * 0.5
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
        background: Rectangle {
            border.width: 2
            color: "transparent"
            radius: albumCoverRaduis
            border.color: Qt.alpha(palette.button, 0.5)
        }
    }
}
